/*
 làm tới sét điều kiện tiền cho ATM
 --> Sét điều kiện số lần giao dich của thẻ
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ATM;

import connect.ConnectDatabase;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import java.sql.*;

/**
 *
 * @author MrTung
 */
public class MainATM extends javax.swing.JFrame {

    ConnectDatabase objConnect = new ConnectDatabase(); //biến kết nối
    String sql;
    String status = "1";//trạng thái form 
    String IDCard = "";
    String PIN = "";
    String TkDoiUng = "";
    String newPIN = "";
    String MaATM = "ATM1";

    /**
     * Creates new form MainATM
     */
    public MainATM() {
        initComponents();
        status = "ChoseLaguage";
        gui_choseLanguage();
    }

    //1
    public void gui_choseLanguage() {
        hide_BL(true, false, false, false, false, false, false, true, true);
        lb_Enter.setVisible(false);
        lbTieuDe.setText("Vui lòng lựa chọn ngôn ngữ");
        lb7.setText("Tiếng Việt");
        lb8.setText("Tiếng Anh");

        txtNhapMa.setVisible(false);
        txtNhapMa.setVisible(false);
    }

    //2
    public void gui_EnterIDcard() {
        hide_BL(true, false, false, false, true, false, false, false, false);
        lb4.setText("Thoát");
        lbTieuDe.setText("Vui lòng nhập mã thẻ");
        lb_Enter.setVisible(true);
        txtNhapMa.setVisible(true);

    }

    //3
    public void gui_EnterPIN() {
        hide_BL(true, false, false, false, true, false, false, false, false);

        lb4.setText("Thoát");
        txtNhapMa.setText("");
        lbTieuDe.setText("Vui lòng nhập PIN của bạn");

        lb_Enter.setVisible(true);
        txtNhapMa.setVisible(true);
        lbSaiMa.setVisible(false);
    }

    //4
    public void gui_SelectTransections() {
        hide_BL(true, true, true, true, true, true, true, true, true);
        lb_Enter.setVisible(false);
        lbSaiMa.setVisible(false);
        txtNhapMa.setVisible(false);
        lb_Note.setVisible(false);

        lbTieuDe.setText("Vui lòng lựa chọn giao dịch");

        lb1.setText("Đổi PIN");
        lb2.setText("Vấn tin tài khoản");
        lb3.setText("Về chúng tôi");
        lb4.setText("Thoát");
        lb5.setText("Rút tiền");
        lb6.setText("Gửi tiền");
        lb7.setText("Chuyển tiền");
        lb8.setText("In sao kê");
    }

    // gui change Pin
    public void gui_ChangePIN() {
        hide_BL(true, false, false, false, true, false, false, false, false);
        lbTieuDe.setText("Vui nhập PIN cũ của bạn");

        txtNhapMa.setVisible(true);
        txtNhapMa.setText("");
    }

    //gui changePIN 2
    public void gui_ChangePIN2() {
        hide_BL(true, false, false, false, true, false, false, false, false);
        lbTieuDe.setText("Vui nhập PIN mới của bạn");

        txtNhapMa.setVisible(true);
        txtNhapMa.setText("");
    }

    //gui changePIN 3
    public void gui_ChangePIN3() {
        hide_BL(true, false, false, false, true, false, false, false, false);
        lbTieuDe.setText("Vui nhập lại PIN mới của bạn");

        txtNhapMa.setVisible(true);
        txtNhapMa.setText("");
    }

    //8 giao dien nút thoát 
    public void gui_Exit() {
        hide_BL(true, false, false, false, false, false, false, true, true);
        lbTieuDe.setText("Bạn có muốn thoát hệ thống");

        lb7.setText("Có");
        lb8.setText("Không");
    }

    //9
    public void gui_CashWithdraw() {
        hide_BL(true, true, true, true, true, true, true, true, true);
        lbTieuDe.setText("Vui lòng chọn số tiền muốn rút");

        lb1.setText("10.000 VNĐ");
        lb2.setText("20.000 VNĐ");
        lb3.setText("50.000 VNĐ");
        lb4.setText("Thoát");
        lb5.setText("100.000 VNĐ");
        lb6.setText("200.000 VNĐ");
        lb7.setText("500.000 VNĐ");
        lb8.setText("Khác");
    }

    //9.1
    public void gui_CashWithdrawOrther() {
        hide_BL(true, false, false, false, true, false, false, false, false);
        lbTieuDe.setText("Vui lòng nhập số lượng tiền muốn rút");
        lb_Note.setText("Là bội của 20 và không quá 5000.0000");
        lb_Note.setVisible(true);
        lb_Enter.setVisible(true);
        txtNhapMa.setVisible(true);
        txtNhapMa.setText("");
    }

    //10
    public void gui_CashDeposit() {
        hide_BL(true, false, false, false, true, false, false, false, false);
        lbTieuDe.setText("Vui lòng nhập số tiền gửi");

        lb_Note.setVisible(true);
        lb_Note.setText("Là bội của 20 và không lớn hơn 5000000");
        txtNhapMa.setVisible(true);
        txtNhapMa.setText("");

        lb_Enter.setVisible(true);
    }

    //11
    public void gui_FundTransfer() {
        hide_BL(true, false, false, false, true, false, false, false, false);
        lbTieuDe.setText("Vui lòng nhập tài khoản đích");
        txtNhapMa.setVisible(true);
        txtNhapMa.setText("");
        lb_Enter.setVisible(true);
    }

    //11.1
    public void gui_FundTransfer2() {
        hide_BL(true, false, false, false, true, false, false, false, false);
        lbTieuDe.setText("Vui lòng nhập tiền muốn chuyển");
        txtNhapMa.setVisible(true);
        txtNhapMa.setText("");
        lb_Enter.setVisible(true);
        lbSaiMa.setVisible(false);
    }

    //Hàm rút tiền
    public void CashWithdraw(String IDCard1, int money) {
        //Connect database
        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "update TaiKhoan set Sodu = SoDu - " + money + " where SoTaiKhoan = (select SoTaiKhoan from The where MaThe ='" + IDCard1 + "')";
            stmt.executeUpdate(sql);
            String Tk = getData(IDCard1, 1).trim();
            sql = "insert into GiaoDich values('" + IDCard1 + "'," + money + ",'VND','" + Tk + "','ATM1','OK','RT',getdate())";
            stmt.executeUpdate(sql);
            sql = "update ATM set SoTienCon = SoTienCon - " + money + "where MaATM = '" + MaATM + "'";
            stmt.executeUpdate(sql);
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //hàm gửi tiền
    public void CashDeposit(String IDCard1, int money) {
        //Connect database
        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "update TaiKhoan set Sodu = SoDu + " + money + " where SoTaiKhoan = (select SoTaiKhoan from The where MaThe ='" + IDCard1 + "')";
            stmt.executeUpdate(sql);
            String Tk = getData(IDCard1, 1).trim();
            sql = "insert into GiaoDich values('" + IDCard1 + "'," + money + ",'VND'," + Tk + ",'ATM1','OK','GT',getdate())";
            stmt.executeUpdate(sql);
            sql = "update ATM set SoTienGui = SoTienGui + " + money + " where MaATM = '" + MaATM + "'";
            stmt.executeUpdate(sql);
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

//
    public void FundTransfer(String IDCard1, int money) {
        //Connect database
        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "update TaiKhoan set Sodu = SoDu + " + money + " where SoTaiKhoan = '" + IDCard1 + "'";
            stmt.executeUpdate(sql);
            sql = "update TaiKhoan set Sodu = SoDu - " + money + " where SoTaiKhoan = (select SoTaiKhoan from The where MaThe ='" + IDCard + "')";
            stmt.executeUpdate(sql);
            String Tk = getData(IDCard, 1).trim();
            sql = "insert into GiaoDich values('" + IDCard + "'," + money + ",'VND'," + TkDoiUng + ",'ATM1','OK','CK',getdate())";
            stmt.executeUpdate(sql);
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //get data in database
    public String getData(String ID, int i) {
        String data = "";
        String sqlGetData = null;
        //Connect database
        ConnectDatabase objConnect = new ConnectDatabase();
        Connection conn = objConnect.connect();
        try {
            Statement stm = conn.createStatement();
            ResultSet rs = null;
            switch (i) { // them cac case de them su lua chon
                case 1: //Ket qua tra ve Ma Tai Khoan.
                    sql = "select SoTaiKhoan from The where MaThe = '" + ID + "'";
                    break;
                case 2://Kết quả trả về số dư
                    sql = "select SoDu from TaiKhoan where SoTaiKhoan=(select SoTaiKhoan from The where MaThe='" + ID + "')";
                    break;
            }//ket thuc switch case
            rs = stm.executeQuery(sql); // đổ dữ liệu ra rs
            while (rs.next()) {
                data = rs.getString(1);
            }// end while
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }

        return data;
    }

    //sét ẩn hiện cho nút và nhãn tương ứng
    public void hide_BL(Boolean t, Boolean b1, Boolean b2, Boolean b3, Boolean b4, Boolean b5, Boolean b6, Boolean b7, Boolean b8) {
        lbTieuDe.setVisible(t);

        lb1.setVisible(b1);
        lb2.setVisible(b2);
        lb3.setVisible(b3);
        lb4.setVisible(b4);
        lb5.setVisible(b5);
        lb6.setVisible(b6);
        lb7.setVisible(b7);
        lb8.setVisible(b8);

        btn1.setVisible(b1);
        btn2.setVisible(b2);
        btn3.setVisible(b3);
        btn4.setVisible(b4);
        btn5.setVisible(b5);
        btn6.setVisible(b6);
        btn7.setVisible(b7);
        btn8.setVisible(b8);
    }
//hàm check mã thẻ đã đúng chưa

    public Boolean checkIDCard(String MaThe) {
        Boolean t = true;
        ResultSet rs = null;
        String data = "";
        // check xem mã thẻ đã đủ 15 số chưa
        if (MaThe.length() > 15) {
            t = false;
            System.out.print("Mã Thẻ ko hợp lên,phải dai 15");
            return t;
        }
        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "select count(MaThe) from The where MaThe = '" + MaThe + "'";
            rs = stmt.executeQuery(sql);
            while (rs.next()) {
                data = rs.getString(1);
            }// end while
            conn.close();//close connect database
            if (!data.equals("1")) {//nếu ko có mã thẻ
                t = false;
                return t;
            }
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }

        return t;
    }

    //Check ACC - 
    public Boolean checkACC(String MaThe) {
        Boolean t = true;
        ResultSet rs = null;
        String data = "";
        // check xem mã thẻ đã đủ 15 số chưa
        if (MaThe.length() > 15) {
            t = false;
            System.out.print("số tài khoản ko hợp lên,phải dai 15");
            return t;
        }

        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "select count(SoTaiKhoan) from TaiKhoan where SoTaiKhoan = '" + MaThe + "'";
            rs = stmt.executeQuery(sql);
            while (rs.next()) {
                data = rs.getString(1);
            }// end while
            conn.close();//close connect database
            if (!data.equals("1")) {//nếu ko có mã thẻ
                t = false;
                return t;
            }
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }
        return t;
    }

    //Check PIN - 
    public Boolean checkPIN(String MaPin) {
        Boolean t = true;
        ResultSet rs = null;
        String data = "";
        // check xem mã thẻ đã đủ 15 số chưa
        if (MaPin.length() > 4) {
            t = false;
            System.out.print("số tài khoản ko hợp lệ");
            return t;
        }

        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "select count(MaPin) from The where MaPin = '" + MaPin + "' and MaThe = '" + IDCard + "'";
            rs = stmt.executeQuery(sql);
            while (rs.next()) {
                data = rs.getString(1);
            }// end while
            conn.close();//close connect database
            if (!data.equals("1")) {//nếu ko có mã thẻ
                t = false;
                return t;
            }
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }
        return t;
    }

    //Check ATM money
    public Boolean CheckATMMoney(String MaATM, int Money) {
        Boolean t = true;
        ResultSet rs = null;
        String data = "";
        //connect database
        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "select SoTienCon from ATM where MaATM = '" + MaATM + "'";
            rs = stmt.executeQuery(sql);
            while (rs.next()) {
                data = rs.getString(1);
            }// end while
            conn.close();//close connect database
            if (Integer.parseInt(data) < Money) {//nếu tiền trong ATM ko đủ thì báo False
                t = false;
                return t;
            }
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }
        return t; // Tiền trong ATM đủ
    }
    //Count transection
    public void CountTransection(String MaThe){
        String sql="";
        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "";
            
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    // Change PIN
    public void ChangePIN(String MaThe, String MaPin) {
        String sql = "";
        Connection conn = objConnect.connect();
        try {
            Statement stmt = conn.createStatement();
            sql = "update The set MaPin= '" + MaPin + "' where MaThe = '" + MaThe + "'";
            stmt.executeUpdate(sql);
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(MainATM.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        btn8 = new javax.swing.JButton();
        btn1 = new javax.swing.JButton();
        btn2 = new javax.swing.JButton();
        btn3 = new javax.swing.JButton();
        btn4 = new javax.swing.JButton();
        btn5 = new javax.swing.JButton();
        btn6 = new javax.swing.JButton();
        btn7 = new javax.swing.JButton();
        lbTieuDe = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lb8 = new javax.swing.JLabel();
        lb1 = new javax.swing.JLabel();
        lb2 = new javax.swing.JLabel();
        lb3 = new javax.swing.JLabel();
        lb4 = new javax.swing.JLabel();
        lb5 = new javax.swing.JLabel();
        lb6 = new javax.swing.JLabel();
        lb7 = new javax.swing.JLabel();
        lb_Enter = new javax.swing.JLabel();
        txtNhapMa = new javax.swing.JTextField();
        lbSaiMa = new javax.swing.JLabel();
        lb_Note = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ATM System");
        setResizable(false);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setOpaque(false);
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btn8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn8ActionPerformed(evt);
            }
        });
        jPanel1.add(btn8, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 340, 50, 50));

        btn1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn1ActionPerformed(evt);
            }
        });
        jPanel1.add(btn1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, 50, 50));

        btn2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn2ActionPerformed(evt);
            }
        });
        jPanel1.add(btn2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 200, 50, 50));

        btn3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn3ActionPerformed(evt);
            }
        });
        jPanel1.add(btn3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 270, 50, 50));

        btn4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn4ActionPerformed(evt);
            }
        });
        jPanel1.add(btn4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 340, 50, 50));

        btn5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn5ActionPerformed(evt);
            }
        });
        jPanel1.add(btn5, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 130, 50, 50));

        btn6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn6ActionPerformed(evt);
            }
        });
        jPanel1.add(btn6, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 200, 50, 50));

        btn7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn7ActionPerformed(evt);
            }
        });
        jPanel1.add(btn7, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 270, 50, 50));

        lbTieuDe.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
        lbTieuDe.setForeground(new java.awt.Color(0, 0, 255));
        lbTieuDe.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbTieuDe.setText("Vui lòng lựa chọn giao dịch");
        jPanel1.add(lbTieuDe, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 30, 540, 40));

        jLabel3.setFont(new java.awt.Font("Times New Roman", 3, 12)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Copyright 2013 - T.Team");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 470, 360, -1));

        lb8.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        lb8.setForeground(new java.awt.Color(0, 0, 255));
        lb8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb8.setText("IN SAO KÊ");
        jPanel1.add(lb8, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 350, 210, 30));

        lb1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        lb1.setForeground(new java.awt.Color(0, 0, 255));
        lb1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lb1.setText("ĐỔI PIN");
        jPanel1.add(lb1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 140, 210, 30));

        lb2.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        lb2.setForeground(new java.awt.Color(0, 0, 255));
        lb2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lb2.setText("VẤN TIN TÀI KHOẢN");
        jPanel1.add(lb2, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 210, 250, 30));

        lb3.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        lb3.setForeground(new java.awt.Color(0, 0, 255));
        lb3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lb3.setText("VỀ CHÚNG TÔI");
        jPanel1.add(lb3, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 280, 210, 30));

        lb4.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        lb4.setForeground(new java.awt.Color(0, 0, 255));
        lb4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lb4.setText("THOÁT");
        jPanel1.add(lb4, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 350, 210, 30));

        lb5.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        lb5.setForeground(new java.awt.Color(0, 0, 255));
        lb5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb5.setText("RÚT TIỀN");
        jPanel1.add(lb5, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 140, 210, 30));

        lb6.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        lb6.setForeground(new java.awt.Color(0, 0, 255));
        lb6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb6.setText("GỬI TIỀN");
        jPanel1.add(lb6, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 210, 210, 30));

        lb7.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        lb7.setForeground(new java.awt.Color(0, 0, 255));
        lb7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb7.setText("CHUYỂN TIỀN");
        jPanel1.add(lb7, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 280, 210, 30));

        lb_Enter.setFont(new java.awt.Font("Times New Roman", 3, 24)); // NOI18N
        lb_Enter.setForeground(new java.awt.Color(255, 0, 0));
        lb_Enter.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb_Enter.setText("Nhấn ENTER để tiếp tục");
        jPanel1.add(lb_Enter, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 400, -1, -1));

        txtNhapMa.setBackground(new java.awt.Color(102, 153, 255));
        txtNhapMa.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        txtNhapMa.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtNhapMa.setToolTipText("Nhập mã thẻ ");
        txtNhapMa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNhapMaKeyPressed(evt);
            }
        });
        jPanel1.add(txtNhapMa, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 150, 370, 50));

        lbSaiMa.setFont(new java.awt.Font("Times New Roman", 2, 18)); // NOI18N
        lbSaiMa.setForeground(new java.awt.Color(255, 0, 0));
        jPanel1.add(lbSaiMa, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 360, 330, 30));

        lb_Note.setFont(new java.awt.Font("Times New Roman", 2, 18)); // NOI18N
        lb_Note.setForeground(new java.awt.Color(255, 0, 0));
        lb_Note.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel1.add(lb_Note, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 80, 380, 40));

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(jPanel1, gridBagConstraints);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Coastal_bg.jpg"))); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(jLabel1, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn7ActionPerformed
        switch (status) {
            case "ChoseLaguage":
                gui_EnterIDcard();
                status = "EnterIDCrad";
                break;
            case "EnterIDCrad":
                break;
            case "EnterPIN":
                break;
            case "SelectTransections":
                gui_FundTransfer();
                status = "FundTransfer";
                break;
            case "ChangePIN":
                break;
            case "ViewACC":
                break;
            case "AboutUS":
                break;
            case "Exit":
                break;
            case "CashWithdraw":
                //Check ATM money
                if (!CheckATMMoney(MaATM, 500000)) {
                    lbSaiMa.setVisible(true);
                    lbSaiMa.setText("Số tiền trong ATM hiện không đủ");
                    break;
                }
                CashWithdraw(IDCard, 500000);// Thực hiện rút tiền
                JOptionPane.showMessageDialog(null, "Giao dịch thành công! Bạn vừa rút 500.000 VNĐ", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "CashDeposit":
                break;
            case "FundTransfer":
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_btn7ActionPerformed
//sự kiện click vào nut 5
    private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn5ActionPerformed
        switch (status) {
            case "ChoseLaguage":
                break;
            case "EnterIDCrad":
                break;
            case "EnterPIN":
                break;
            case "SelectTransections":
                status = "CashWithdraw";
                gui_CashWithdraw();
                break;
            case "ChangePIN":
                break;
            case "ViewACC":
                break;
            case "AboutUS":
                break;
            case "Exit":
                break;
            case "CashWithdraw":
                //Check ATM money
                if (!CheckATMMoney(MaATM, 100000)) {
                    lbSaiMa.setVisible(true);
                    lbSaiMa.setText("Số tiền trong ATM hiện không đủ");
                    break;
                }
                CashWithdraw(IDCard, 100000);// Thực hiện rút tiền
                JOptionPane.showMessageDialog(null, "Giao dịch thành công! Bạn vừa rút 100.000 VNĐ", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "CashDeposit":
                break;
            case "FundTransfer":
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_btn5ActionPerformed

    //sự kiện click vào nút 4
    private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn4ActionPerformed
        switch (status) {
            case "ChoseLaguage": //chọn ngôn ngữ
                break;
            case "EnterIDCrad"://nhập mã thẻ
                gui_choseLanguage();//chuyen ve giao dien chon ngon ngu
                status = "ChoseLaguage";//chuyen  trang thai 
                break;
            case "EnterPIN"://nhập mã pin
                gui_EnterIDcard();
                status = "EnterIDCrad";
                break;
            case "SelectTransections"://chọn giao dịch
                gui_Exit();
                status = "Exit";
                break;
            case "ChangePIN"://thay đổi pin
                gui_SelectTransections();
                status = "SelectTransections";
                break;
            case "ChangePIN2":
                gui_SelectTransections();
                status = "SelectTransections";
                break;
            case "ChangePIN3":
                gui_SelectTransections();
                status = "SelectTransections";
                break;
            case "ViewACC"://xem thông tin tài khoản
                break;
            case "AboutUS"://thông tin về chúng tôi
                break;
            case "Exit"://thoát
                break;
            case "CashWithdraw"://rút tiền
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "CashWithdrawOrther":
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "CashDeposit"://gửi tiền
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "FundTransfer"://chuyển khoản
                gui_SelectTransections();
                status = "SelectTransections";
                break;
            case "FundTransfer2":
                gui_SelectTransections();
                status = "SelectTransections";
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_btn4ActionPerformed

    private void txtNhapMaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNhapMaKeyPressed
        switch (status) {
            case "ChoseLaguage":
                break;
            case "EnterIDCrad":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    System.out.print(txtNhapMa.getText());
                    if (!checkIDCard(txtNhapMa.getText())) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Mã thẻ bạn vừa nhập không hợp lệ");
                        txtNhapMa.selectAll();
                        break;
                    }
                    status = "EnterPIN";
                    IDCard = txtNhapMa.getText();
                    gui_EnterPIN();
                }
                break;
            case "EnterPIN":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (txtNhapMa.getText().equals("")) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Mã PIN bạn vừa nhập không hợp lệ");
                        txtNhapMa.selectAll();
                        break;
                    }
                    status = "SelectTransections";
                    PIN = txtNhapMa.getText();
                    gui_SelectTransections();
                }
            case "SelectTransections":
                break;
            case "ChangePIN":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (txtNhapMa.getText().equals("")) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Mã PIN bạn vừa nhập không hợp lệ");
                        txtNhapMa.selectAll();
                        break;
                    }
                    // check  old PIN
                    if (checkPIN(txtNhapMa.getText())) {
                        gui_ChangePIN2();
                        status = "ChangePIN2";
                        break;
                    }
                    lbSaiMa.setVisible(true);
                    lbSaiMa.setText("Mã PIN Sai, Vui lòng nhập lại");
                    txtNhapMa.selectAll();
                }
                break;
            case "ChangePIN2":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (txtNhapMa.getText().length() > 4 || txtNhapMa.getText().length() == 0) {
                        lbSaiMa.setText("Max Pin gồm 4 chữ số, Vui lòng nhập lại");
                        txtNhapMa.setText("");
                        txtNhapMa.selectAll();
                        lbSaiMa.setVisible(true);
                        break;
                    }
                    if (txtNhapMa.getText().equals("")) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Mã PIN bạn vừa nhập không hợp lệ");
                        txtNhapMa.selectAll();
                        break;
                    }
                    newPIN = txtNhapMa.getText();
                    gui_ChangePIN3();
                    status = "ChangePIN3";
                }
                break;
            case "ChangePIN3":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (txtNhapMa.getText().equals(newPIN)) {
                        ChangePIN(IDCard, txtNhapMa.getText());
                        gui_SelectTransections();
                        status = "SelectTransections";
                        break;
                    }
                    lbSaiMa.setText("Ma PIN không khớp, Vui lòng nhập lại");
                    txtNhapMa.selectAll();
                }
                break;
            case "ViewACC":
                break;
            case "AboutUS":
                break;
            case "Exit":
                break;
            case "CashWithdraw":
                break;
            case "CashWithdrawOrther":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (!CheckATMMoney(MaATM, Integer.parseInt(txtNhapMa.getText()))) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("ATM khong du tien thuc hien giao dich");
                        txtNhapMa.selectAll();
                        break;
                    }
                    if (txtNhapMa.getText().equals("") || (Integer.parseInt(txtNhapMa.getText()) % 20) != 0 || Integer.parseInt(txtNhapMa.getText()) > 5000000) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Lượng tiền nhập vào không hợp lệ");
                        txtNhapMa.selectAll();
                        break;
                    }

                    CashWithdraw(IDCard, Integer.parseInt(txtNhapMa.getText().trim()));

                    JOptionPane.showMessageDialog(null, "Giao dịch thành công", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                    status = "SelectTransections";
                    gui_SelectTransections();
                }
                break;
            case "CashDeposit":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (txtNhapMa.getText().equals("") || (Integer.parseInt(txtNhapMa.getText()) % 20) != 0 || Integer.parseInt(txtNhapMa.getText()) > 5000000) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Lượng tiền nhập vào không hợp lệ");
                        txtNhapMa.selectAll();
                        break;
                    }

                    CashDeposit(IDCard, Integer.parseInt(txtNhapMa.getText()));

                    JOptionPane.showMessageDialog(null, "Giao dịch thành công", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                    status = "SelectTransections";
                    gui_SelectTransections();
                }
                break;
            case "FundTransfer":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (txtNhapMa.getText().equals("")) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Số tài khoản nhập không hợp lệ - Vui lòng thử lại");
                        txtNhapMa.selectAll();
                        break;
                    }
                    if (!checkACC(txtNhapMa.getText())) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Số tài khoản nhập không hợp lệ - Vui lòng thử lại");
                        txtNhapMa.selectAll();
                        break;
                    }
                    TkDoiUng = txtNhapMa.getText();
                    status = "FundTransfer2";
                    gui_FundTransfer2();
                }
                break;
            case "FundTransfer2":
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (txtNhapMa.getText().equals("")) {
                        lbSaiMa.setVisible(true);
                        lbSaiMa.setText("Số tiền nhập không hợp lệ - Vui lòng thử lại");
                        txtNhapMa.selectAll();
                        break;
                    }
                    FundTransfer(TkDoiUng, Integer.parseInt(txtNhapMa.getText()));
                    JOptionPane.showMessageDialog(null, "Giao dịch thành công", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                    status = "SelectTransections";
                    gui_SelectTransections();
                }
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_txtNhapMaKeyPressed
//Even: click on btn7
    private void btn8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn8ActionPerformed
        switch (status) {
            case "ChoseLaguage":
                break;
            case "EnterIDCrad":
                break;
            case "EnterPIN":
                break;
            case "SelectTransections":
                break;
            case "ChangePIN":
                break;
            case "ViewACC":
                break;
            case "AboutUS":
                break;
            case "Exit"://thoát
                gui_SelectTransections();
                status = "SelectTransections";
                break;
            case "CashWithdraw":
                status = "CashWithdrawOrther";
                gui_CashWithdrawOrther();
                break;
            case "CashWithdrawOrther":
                break;
            case "CashDeposit":
                break;
            case "FundTransfer":
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_btn8ActionPerformed
//even click on btn1
    private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn1ActionPerformed
        switch (status) {
            case "ChoseLaguage":
                break;
            case "EnterIDCrad":
                break;
            case "EnterPIN":
                break;
            case "SelectTransections":
                gui_ChangePIN();
                status = "ChangePIN";
                break;
            case "ChangePIN":;
                break;
            case "ViewACC":
                break;
            case "AboutUS":
                break;
            case "Exit":
                break;
            case "CashWithdraw":
                //Check ATM money
                if (!CheckATMMoney(MaATM, 10000)) {
                    lbSaiMa.setVisible(true);
                    lbSaiMa.setText("Số tiền trong ATM hiện không đủ");
                    break;
                }
                CashWithdraw(IDCard, 10000);// Thực hiện rút tiền
                JOptionPane.showMessageDialog(null, "Giao dịch thành công! Bạn vừa rút 10.000 VNĐ", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "CashWithdrawOrther":
                break;
            case "CashDeposit":
                break;
            case "FundTransfer":
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_btn1ActionPerformed
//even click on btn2
    private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn2ActionPerformed
        switch (status) {
            case "ChoseLaguage":
                break;
            case "EnterIDCrad":
                break;
            case "EnterPIN":
                break;
            case "SelectTransections":

            case "ChangePIN":
                break;
            case "ViewACC":
                break;
            case "AboutUS":
                break;
            case "Exit":
                break;
            case "CashWithdraw":
                //Check ATM money
                if (!CheckATMMoney(MaATM, 20000)) {
                    lbSaiMa.setVisible(true);
                    lbSaiMa.setText("Số tiền trong ATM hiện không đủ");
                    break;
                }
                CashWithdraw(IDCard, 20000);// Thực hiện rút tiền
                JOptionPane.showMessageDialog(null, "Giao dịch thành công! Bạn vừa rút 20.000 VNĐ", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "CashWithdrawOrther":
                break;
            case "CashDeposit":
                break;
            case "FundTransfer":
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_btn2ActionPerformed
//Even click on btn3
    private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn3ActionPerformed
        switch (status) {
            case "ChoseLaguage":
                break;
            case "EnterIDCrad":
                break;
            case "EnterPIN":
                break;
            case "SelectTransections":

            case "ChangePIN":
                break;
            case "ViewACC":
                break;
            case "AboutUS":
                break;
            case "Exit":
                break;
            case "CashWithdraw":
                //Check ATM money
                if (!CheckATMMoney(MaATM, 50000)) {
                    lbSaiMa.setVisible(true);
                    lbSaiMa.setText("Số tiền trong ATM hiện không đủ");
                    break;
                }
                CashWithdraw(IDCard, 50000);// Thực hiện rút tiền
                JOptionPane.showMessageDialog(null, "Giao dịch thành công! Bạn vừa rút 50.000 VNĐ", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "CashWithdrawOrther":
                break;
            case "CashDeposit":
                break;
            case "FundTransfer":
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_btn3ActionPerformed
//Even click on btn6
    private void btn6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn6ActionPerformed
        switch (status) {
            case "ChoseLaguage":
                break;
            case "EnterIDCrad":
                break;
            case "EnterPIN":
                break;
            case "SelectTransections":
                gui_CashDeposit();
                status = "CashDeposit";
                break;
            case "ChangePIN":
                break;
            case "ViewACC":
                break;
            case "AboutUS":
                break;
            case "Exit":
                break;
            case "CashWithdraw"://rút tiền
                //Check ATM money
                if (!CheckATMMoney(MaATM, 200000)) {
                    lbSaiMa.setVisible(true);
                    lbSaiMa.setText("Số tiền trong ATM hiện không đủ");
                    break;
                }
                CashWithdraw(IDCard, 200000);// Thực hiện rút tiền
                JOptionPane.showMessageDialog(null, "Giao dịch thành công! Bạn vừa rút 200.000 VNĐ", "Quan tri he thong", JOptionPane.INFORMATION_MESSAGE);
                status = "SelectTransections";
                gui_SelectTransections();
                break;
            case "CashWithdrawOrther":

                break;
            case "CashDeposit":

                break;
            case "FundTransfer":
                break;
            case "MiniStatement":
                break;
        }
    }//GEN-LAST:event_btn6ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainATM().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn1;
    private javax.swing.JButton btn2;
    private javax.swing.JButton btn3;
    private javax.swing.JButton btn4;
    private javax.swing.JButton btn5;
    private javax.swing.JButton btn6;
    private javax.swing.JButton btn7;
    private javax.swing.JButton btn8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lb1;
    private javax.swing.JLabel lb2;
    private javax.swing.JLabel lb3;
    private javax.swing.JLabel lb4;
    private javax.swing.JLabel lb5;
    private javax.swing.JLabel lb6;
    private javax.swing.JLabel lb7;
    private javax.swing.JLabel lb8;
    private javax.swing.JLabel lbSaiMa;
    private javax.swing.JLabel lbTieuDe;
    private javax.swing.JLabel lb_Enter;
    private javax.swing.JLabel lb_Note;
    private javax.swing.JTextField txtNhapMa;
    // End of variables declaration//GEN-END:variables
}
